package com.fancy.social.controller;

import com.fancy.social.dto.CommentCreateDTO;
import com.fancy.social.service.CommentService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "评论管理")
@RestController
@RequestMapping("/api/v1/comments")
@RequiredArgsConstructor
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "发表评论", notes = "用户对歌曲、专辑、歌单或动态发表评论")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "long"),
        @ApiImplicitParam(name = "targetId", value = "目标ID", required = true, paramType = "query", dataType = "long"),
        @ApiImplicitParam(name = "targetType", value = "目标类型(song/album/playlist/dynamic)", required = true, paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "content", value = "评论内容", required = true, paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "parentId", value = "父评论ID（回复评论时使用）", paramType = "query", dataType = "long", example = "0")
    })
    @PostMapping
    public ResponseEntity<Void> createComment(@RequestHeader("X-User-Id") Long userId, @RequestBody CommentCreateDTO commentCreateDTO) {
        commentService.createComment(userId, commentCreateDTO);
        return ResponseEntity.ok().build();
    }

    @ApiOperation(value = "删除评论", notes = "用户删除自己发表的评论")
    @ApiImplicitParam(name = "commentId", value = "评论ID", required = true, paramType = "path", dataType = "long")
    @DeleteMapping("/{commentId}")
    public ResponseEntity<Void> deleteComment(@RequestHeader("X-User-Id") Long userId, @PathVariable Long commentId) {
        commentService.deleteComment(userId, commentId);
        return ResponseEntity.ok().build();
    }
}
